package com.xlkj.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;


public class HomeReceiver extends BroadcastReceiver {
    static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
    static public final String SYSTEM_DIALOG_REASON_RECENT_KEY = "recentapps";
    static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        //屏幕点亮
        if(action.equals(Intent.ACTION_SCREEN_ON)) {
            PowerUtil.unlockDevice(context);
            PowerUtil.restartApp(context);
        //屏幕熄灭
        }else if(action.equals(Intent.ACTION_SCREEN_OFF)){
              PowerUtil.restartApp(context);
        //屏幕唤醒
        }else if(action.equals(Intent.ACTION_USER_PRESENT)){
            PowerUtil.unlockDevice(context);
            PowerUtil.restartApp(context);
        //监听home和menu键
        }else if(action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)){
            String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
            if(reason!=null){
                //点home键
                if(reason.equals(SYSTEM_DIALOG_REASON_HOME_KEY)){
                    PowerUtil.restartApp(context);
                //点menu键
                }else if(reason.equals(SYSTEM_DIALOG_REASON_RECENT_KEY)){
                    //PowerUtil.restartApp(context);
                }else {
                    Log.e("err","ACTION_CLOSE_SYSTEM_DIALOGS-->:"+reason);
                }
            }
        }else{
            Log.e("err","action: "+action);
        }
    }


}
